import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import left_menu from'../components/Menu.vue'
// import bottomBar from "../components/bottomBar.vue";
const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    meta:{
      isShowBottomBar:true,//导航栏在该页面显示
      isShowTopSearch:true,//搜索歌曲在当前页面展示
    },
    children:[
      {path:'',component:left_menu},
      // {path:'',component:bottomBar}
    ]
  },
  {
    //icon 每日推荐
    path: '/daily_music',
    name: 'daily_music',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Daily_Music.vue'),
    meta:{
      isShowBottomBar:true,
      isShowTopSearch:false,
      isShowTopBar:true,
      topBarTitle:'每日推荐',
      isShowRight:false,
    },
  },
  {
    path: '/personal_live',
    name: 'personal_live',
    component: ()=>import('../views/Personal_live.vue'),
    meta:{
      isShowBottomBar:true,
      isShowTopSearch:false,
      isShowTopBar:true,
      topBarTitle:'私人漫游',
      isShowRight:false,
    },
  },
  {
    path: '/music_menu',
    name: 'music_menu',
    component: ()=>import('../views/Music_Menu.vue'),
    meta:{
      isShowBottomBar:true,
      isShowTopSearch:false,
      isShowTopBar:true,
      topBarTitle:'歌单广场',
      isShowRight:false,
    },
  },
  {
    path: '/charts',
    name: 'charts',
    component: ()=>import('../views/Charts.vue'),
    meta:{
      isShowBottomBar:true,
      isShowTopSearch:false,
      isShowTopBar:true,
      topBarTitle:'排行榜',
      isShowRight:false,
    },
  },
  {
    path: '/audiobook',
    name: 'audiobook',
    component: ()=>import('../views/Audiobook.vue'),
    meta:{
      isShowBottomBar:true,
      isShowTopSearch:false,
      isShowTopBar:true,
      topBarTitle:'有声书',
      isShowRight:false,
    },
  },
  {
    path: '/minePage',
    name: 'minePage',
    component: ()=>import('../views/mine.vue'),
    meta:{
      isShowBottomBar:true,
      isShowTopSearch:false,
    },
  },
  {
    path: '/boke',
    name: 'boke',
    component: ()=>import('../views/boke.vue'),
    meta:{
      isShowBottomBar:true,
      isShowTopSearch:false,
    },
  },
  {
    path: '/guanzhu',
    name: 'guanzhu',
    component: ()=>import('../views/guanzhu.vue'),
    meta:{
      isShowBottomBar:true,
      isShowTopSearch:false,
    },
  },
  {
    path: '/shequ',
    name: 'shequ',
    component: ()=>import('../views/shequ.vue'),
    meta:{
      isShowBottomBar:true,
      isShowTopSearch:false,
    },
  },
  {
    path: '/login',
    name: 'login',
    component: ()=>import('../views/login.vue'),
    meta:{
      isShowBottomBar:false,//导航栏在该页面不显示
      isShowTopSearch:false,
    },
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

//路由守卫，判断是否登录
//   router.beforeEach((to,from,next)=>{
//     /* 
//   router.beforeEach() 进入之前触发
//   router.afterEach() 进入之后触发
//   每个守卫方法接收三个参数：
//   to: Route: 即将要进入的目标路由对象
//   （to是一个对象，是将要进入的路由对象，可以用to.path调用路由对象中的属性）
//   from: Route: 当前导航正要离开的路由
//   next: Function: 这是一个必须需要调用的方法，执行效果依赖 next 方法的调用参数。
//   */
//  //判断用户是否登录
//     const uInfo = store.state.uInfo.userInfo
//     if(!uInfo.username) {
//       //未登录,跳转到login
//        if(to.path ==="/login"){
//         //防止在login页面一直死循环
//         next()
//         return
//        }
//        next("/login")
//     } else{
//          next()
//     }
 
//   })

export default router
